package com.tang.algorithm.doublePointer;

/**
 * @author tlm
 * @version 1.0
 * @date 2020/7/8 21:20
 */
public class LeetCode977 {
    public int[] sortedSquares(int[] A) {
        int[] arrs=new int[A.length];
        int left,right,nowIndex;
        left=0;
        right=nowIndex=A.length-1;
        while (left<=right){
            int lValue=A[left]<0?-A[left]:A[left];
            int rValue=A[right]<0?-A[right]:A[right];
            if (lValue<rValue){
                arrs[nowIndex--]=rValue*rValue;
                right--;
            }else {
                arrs[nowIndex--]=lValue*lValue;
                left++;
            }
        }
        return arrs;
    }
}
